from google.appengine.ext import db

class Classifier(db.Model):
    name = db.StringProperty(required=True)
  
class Item(db.Model):
    classifier = db.ReferenceProperty(Classifier, required=True) 
    name = db.StringProperty(required=True)
    creator = db.UserProperty(required=False)
    create_date = db.DateProperty(auto_now_add=True)
    ip = db.StringProperty(required=True)
      
class Location(db.Model):    
    item = db.ReferenceProperty(Item, required=True)
    description = db.StringProperty(required=True)
    latitude = db.StringProperty(required=True)
    longitude = db.StringProperty(required=True)  
    creator = db.UserProperty(required=False)
    create_date = db.DateProperty(auto_now_add=True)
    number_of_votes = db.IntegerProperty(default=0)
    vote_total = db.IntegerProperty(default=0)
    
    def rating(self):
        if self.number_of_votes==0: 
            return 0
        
        return (float(self.vote_total)/self.number_of_votes)
